import random
str = 'helloWorld';
#序列切片操作
print (str[0:5:1])  # hello
print (str[1:5:1])  # ello
print (str[:5:1])   # hello
print (str[1::1])   # elloWorld
print (str[::1])    #helloworld
print (str[1::])    #elloworld
print (str[::2])    #hlool
print (str[::-1])   #dlrowolleh
print (str[:len(str):]) # helloworld
print (str[-1:-len(str)-1:-1]) #dlrowolleh
print (str[::-1],'与上面结果相同')
print (str,'-原序列')


# 列表的创建
lst = ['ab','cd', 'ef', 28, 29.1]
print (lst)

list1 = list(range(1,10,2)) #从1开始，到10， 步长为2步
print (list1)

print (lst+list1, '列表连接')
print(len(lst))

# 枚举列表
for index, item in enumerate(lst):
    print (index,item)

# 动态创建列表
arr = list(range(1,10))
print(arr, '===动态创建')

# 循环生成
arr2= list(item for item in range(1,10))
print(arr2)

#判断生成
arr3 = list(item for item in range(0,10) if item % 2 == 0)
print(arr3)

#随机生成，并判断
arr4 = list (random.randint(1,1000) for item in range(1,10))
print(arr4)

# 二维列表循环
arr5 = [[1,2,3],[4,5,6]]
print(arr5)
for item in arr5:
    for item2 in item:
        print(item2,end=' ')
    print()

#动态生成二维列表
arr6 = [[j for j in range(i)] for i in range(1,10)]
print(arr6)

